// import { login as loginApi } from '@/api/userMG';
import router from '@/router';
import { setTokenTime } from '@/utils/auth';

export default {
  namespaced: true,  // 命名空间
  state: () => ({
    token: localStorage.getItem('token') || '',
    user: false,
  }),
  mutations: {
    setToken: (state,token) => {
      state.token = token;
      localStorage.setItem('token', token);
    },
    // 登录验证
    login(state, user) {
      state.user = user;
      setTokenTime();
      localStorage.setItem("userInfo", user);
    },
    // 退出
    logout(state) {
      state.user = "";
      localStorage.setItem("userInfo", "");
    }
  },
  actions: {
    // login({ commit },userInfo) {
    //   return new Promise((resolve,reject) => {
    //     this.$http.userMG.loginApi(userInfo).then(res => {
    //       // console.log(res);
    //       commit('setToken',res.token);
    //       setTokenTime();
    //       router.replace('/');
    //       resolve()
    //     })
    //     .catch((err) => {
    //       console.log(err)
    //     })
    //   })
    // },
    // // 退出
    // logout({commit}) {
    //   commit('setToken', '');
    //   localStorage.clear()
    //   router.replace('/login')
    // }
  }
}
